package com.xubeizhi.controller;

import com.xubeizhi.common.Result;
import com.xubeizhi.entity.Product;
import com.xubeizhi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;


    @PostMapping("/create")
    private Result insertProduct(@RequestBody Product product){
        return productService.createProduct(product);
    }

    @PostMapping("/sold")
    private Result soldProduct(@RequestBody Product product){
        return productService.soldProduct(product);
    }

    @PostMapping("/update")
    private Result updateProductById(Product product){
        return productService.updateProductById(product);
    }

    @GetMapping("/list")
    private Result listProduct(Integer pageNum,Integer pageSize,String status,String removeStatus){
        return productService.listProduct(pageNum,pageSize,status,removeStatus);
    }

    @GetMapping("/search")
    private Result searchProductList(String productName,String status,String removeStatus){
        return productService.searchProduct(productName,status,removeStatus);
    }

    @PostMapping("/remove")
    private Result removeProduct(Product product){
        return productService.removeProduct(product);
    }
}
